package member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import member.domain.MemberLevel;
import member.service.MemberLevelService;
import member.mapper.MemberLevelMapper;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author panghu
 * @description 针对表【ums_member_level(会员等级)】的数据库操作Service实现
 * @createDate 2023-03-04 21:04:05
 */
@Service
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelMapper, MemberLevel>
        implements MemberLevelService {

    @Override
    public Page<MemberLevel> queryPage(Map<String, Object> params) {
        LambdaQueryWrapper<MemberLevel> queryWrapper = getQueryWrapper(params);
        Page<MemberLevel> page = new Page<>(Integer.parseInt((String) params.get("page")), Integer.parseInt((String) params.get("limit")));
        return this.baseMapper.selectPage(page, queryWrapper);
    }

    public LambdaQueryWrapper<MemberLevel> getQueryWrapper(Map<String, Object> params) {
        LambdaQueryWrapper<MemberLevel> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(params.containsKey("key"), MemberLevel::getId, params.get("key")).or().like(params.containsKey("key"), MemberLevel::getName, params.get("key"));
        return wrapper;
    }


}




